import { useLocation, Navigate } from "react-router-dom";
import { searchRoute } from "../../units/units";
import { rootRouter } from "../../routers/index";


/**
 * @description 路由守卫组件
 * */
const AuthRouter = (props) => {
	const { pathname } = useLocation();
	const route = searchRoute(pathname, rootRouter);
	// * 判断当前路由是否需要访问权限(不需要权限直接放行)
	if (!route.meta?.requiresAuth) return props.children;

	return props.children;
};

export default AuthRouter;
